package pers.wz;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;

public class NIOClient2 {
    public static void main(String[] args) throws IOException, InterruptedException {
        while (true){
            Thread.sleep(2000);
            SocketChannel socketChannel = SocketChannel.open();
            socketChannel.connect(new InetSocketAddress("127.0.0.1", 9999));
            socketChannel.write(ByteBuffer.wrap("还钱".getBytes(StandardCharsets.UTF_8)));
            ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
            int read = socketChannel.read(byteBuffer);
            System.out.println("服务器消息：" + new String(byteBuffer.array(), 0, read, StandardCharsets.UTF_8));
            socketChannel.close();
        }
    }


}
